package Test06;

import java.io.*;
import java.util.*;

//IO流练习
/*
    需求:把《出师表》的文章顺序进行恢复到一个新文件中。
 */
public class Test24Case02 {
    public static void main(String[] args) throws IOException {

        //1、读取数据
        BufferedReader br = new BufferedReader(new FileReader("D:\\工作\\src\\csb.txt"));
        TreeMap<Integer, String> tm = new TreeMap<>();
        String line;
        while ((line = br.readLine()) != null) {
            String[] arr = line.split("\\.");
            //tm.put(Integer.parseInt(arr[0]), arr[1]);
            tm.put(Integer.parseInt(arr[0]), line);
        }

        //2、写出数据
        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\工作\\src\\csbCopy.txt"));
        Set<Map.Entry<Integer, String>> entries = tm.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            String value = entry.getValue();
            bw.write(value);
            bw.newLine();
        }

        //3、释放资源
        bw.close();
        br.close();
    }
}
